<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="../../css/style.css" rel="stylesheet" type="text/css">

</head>
<body onload="showConditionCustomer()">
<div class="page_title">客户信息管理</div>
<div class="button_bar">
	<button class="common_button" onclick="help('');">帮助</button>
	<button class="common_button" onclick="showConditionCustomer()">查询</button>
</div>
<table class="query_form_table">
	<tr>
		<th>客户编号</th>
		<td><input name="cstNo" /></td>
		<th>名称</th>
		<td><input name="cstName"/></td>
		<th>地区</th>
		<td>
			<select id="region">
				<option>全部</option>
			</select>
		</td>
	</tr>
	<tr>
		<th>客户经理</th>
		<td><input name="cstManagerName" /></td>
		<th>客户等级</th>
		<td>
			<select id="level">
				<option value="">全部</option>
			</select>
		</td>
		<th>　</th>
		<td>　</td>
	</tr>
</table>
<br />
<table class="data_list_table">
	<thead>
	<tr>
		<th>序号</th>
		<th>客户编号</th>
		<th>名称</th>
		<th>地区</th>
		<th>客户经理</th>
		<th>客户等级</th>
		<th>操作</th>
	</tr>
	</thead>
<tbody id="showAll">

</tbody>
	<tr>
		<th colspan="100" class="pager">
<div class="pager">
	共59条记录 每页<input value="10" size="2" />条
	第<input value="1" size="2"/>页/共5页
	<a href="#">第一页</a>
	<a href="#">上一页</a>
	<a href="#">下一页</a>
	<a href="#">最后一页</a>
	转到<input value="1" size="2" />页
	<button width="20" onclick="reload();">GO</button>
</div>
		</th>
	</tr>
</table>
<script src="../../js/jquery-1.9.0.js"></script>
<script>

    <%-- 选择下拉框显示所有不重复地区 --%>
    $(function(){
        $.get("/CstSustomer/selectSingleCustRegion",function (strRegion) {
            var region = $("#region");
            $.each(strRegion,function (i, item) {
                region.append('<option value="' + item + '">' + item + '</option>');
            })
        },"json");
    });

    <%-- 选择下拉框显示所有不重复客户等级 --%>
    $(function(){
        $.get("/CstSustomer/selectSingleCustLevel",function (strLevel) {
            var level = $("#level");
            $.each(strLevel,function (i, item) {
                level.append('<option value="' + item + '">' + item+ '</option>');
            })
        },"json");
    });

    <%-- 通过页面查询条件显示客户信息 --%>
    function showConditionCustomer() {
        $("#showAll").html("");
        var cstNo=$.trim($("input[name=cstNo]").val());
        var cstName=$.trim($("input[name=cstName]").val());
        var cstManagerName=$.trim($("input[name=cstManagerName]").val());
        var optionRegion=$.trim($("#region option:selected").text());  //获取地区选中的项的文本
        var optionLevel=$.trim($("#level option:selected").text());  //获取客户等级选中的项的文本
		if(optionRegion=="全部"){
            optionRegion=null;
		}
        if(optionLevel=="全部"){
            optionLevel=null;
        }
        $.ajax({
            url:"/CstSustomer/selectByCondition",
			data:{
                custNo:cstNo,
                custName:cstName,
                custRegion:optionRegion,
                custManagerName:cstManagerName,
                custLevelLabel:optionLevel
			},
            dataType:'json',
            contentType:"application/json;charset=utf-8",
            success:function (conditionCust) {
                $.each(conditionCust,function (i,customer) {
                    var tr=
                        "<tr>"+
                        "<td>"+(i+1) +"</td>"+
                        "<td>"+customer.custNo+"</td>"+
                        "<td>"+customer.custName+"</td>"+
                        "<td>"+customer.custRegion+"</td>"+
                        "<td>"+customer.custManagerName+"</td>"+
                        "<td>"+customer.custLevelLabel+"</td>"+
                        "<td class='list_data_op'>"+
                        "<a href='edit.html?custNo="+customer.custNo+"'><img title='编辑' src='../../images/bt_edit.gif' class='op_button' /></a>"+
                        "<a href='linkman.html?custNo="+customer.custNo+"'><img title='联系人' src='../../images/bt_linkman.gif' class='op_button' /></a>"+
                        "<a href='activities.jsp?atvCustNo="+customer.custNo+"&atvCustName="+customer.custName+"'><img title='交往记录' src='../../images/bt_acti.gif' class='op_button' /></a>"+
                        "<a href='orders.html?custNo="+customer.custNo+"'><img title='历史订单' src='../../images/bt_orders.gif' class='op_button' /></a>"+
                        "<a href='custNo="+customer.custNo+"'><img title='删除' src='../../images/bt_del.gif' class='op_button' /></a>"+"</td>"+
                        "</tr>"
                    $("#showAll").append(tr);
                })
            }
        })
    }

</script>

</body>
</html>
